feat(mysql): Add database analyzer for MySQL#4201
Draft
kyleconroy wants to merge 2 commits intomainfrom
Draft
Conversation
Adds a MySQL database analyzer that validates queries against a real MySQL
database during code generation. This is similar to the existing PostgreSQL
and SQLite analyzers.
Key features:
- Creates managed databases (sqlc_managed_{hash}) based on migration content
- Validates query syntax using PrepareContext against real MySQL
- Detects parameter count from ? placeholders
- Gracefully handles missing database connections
Also fixes several MySQL test cases to use correct MySQL syntax:
- Changed $1/$2 placeholders to ? (MySQL syntax)
- Added AS aliases to count(*) expressions in CTEs
- Fixed column references and table aliases
- Removed PostgreSQL-specific public. schema prefix
Tests requiring MySQL-specific features (HeatWave VECTOR functions, SHOW
WARNINGS in prepared statements, etc.) are restricted to base context.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
3fc8768 to
e52cd4e
Compare
Updates the MySQL analyzer to use the sqlc-dev/mysql forked driver which exposes column and parameter metadata from COM_STMT_PREPARE responses. This provides more accurate type information directly from MySQL. The forked driver adds a StmtMetadata interface with ColumnMetadata() and ParamMetadata() methods that return type info including DatabaseTypeName, Nullable, Unsigned, and Length fields. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sqlc_managed_{hash}) based on migration content hash for cachingPrepareContextagainst real MySQLImplementation Details
The MySQL analyzer (
internal/engine/dolphin/analyzer/analyze.go) follows the same pattern as the SQLite analyzer:PrepareContextto validate queries against the real databaseTest Fixes
Fixed MySQL test cases that were using PostgreSQL-specific syntax:
$1/$2placeholders to?(MySQL syntax)AS countaliases tocount(*)expressions in CTEsauthor_id→id,authors.parent_id→a.parent_id)public.schema prefixTests restricted to
basecontext (incompatible with real MySQL):mysql_vector- requires MySQL HeatWave (DISTANCE/STRING_TO_VECTOR functions)vet_explain- requires MySQL env vars for explain rulesshow_warnings- SHOW WARNINGS not supported in prepared statementsselect_subquery_no_alias- MySQL requires derived tables to have aliasesvalid_group_by_reference- MySQL's ONLY_FULL_GROUP_BY mode incompatibilityinsert_select_invalid,invalid_group_by_reference,invalid_table_alias- expected error messages differTest plan
go test ./...)go test --tags=examples -timeout 20m ./internal/endtoend/...)🤖 Generated with Claude Code